package org.xx.armory.swing.components;

import java.awt.*;

public final class GBC
        extends GridBagConstraints {
    public GBC(
            int gridx,
            int gridy
    ) {
        this(gridx, gridy, 1, 1);
    }

    public GBC(
            int gridx,
            int gridy,
            int gridwith,
            int gridheight
    ) {
        this.gridx = gridx;
        this.gridy = gridy;
        this.gridwidth = gridwith;
        this.gridheight = gridheight;
        this.weightx = 100;
        this.weighty = 100;
        this.insets.set(2, 2, 2, 2);
    }

    public final GBC setFill(
            int value
    ) {
        this.fill = value;
        return this;
    }

    public final GBC setAnchor(
            int value
    ) {
        this.anchor = value;
        return this;
    }

    public final GBC setMargin(
            int value
    ) {
        this.insets.set(value, value, value, value);
        return this;
    }

    public final GBC setWeightX(
            int value
    ) {
        this.weightx = value;
        return this;
    }

    public final GBC setWeightY(
            int value
    ) {
        this.weighty = value;
        return this;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        final String row = this.gridheight == 1 ? String.valueOf(this.gridy) : (this.gridy + "-" + (this.gridy + this.gridheight - 1));
        final String column = this.gridwidth == 1 ? String.valueOf(this.gridx) : (this.gridx + "-" + (this.gridx + this.gridwidth - 1));
        return "[" + row + "," + column + "]";
//        return "{ x = " + this.gridx + ", y = " + this.gridy
//                + ", width = " + this.gridwidth + ", height = " + this.gridheight
//                + ", weight-x = " + this.weightx + ", weight-y = " + this.weighty
//                + ", fill = " + this.fill + ", anchor = " + this.anchor
//                + ", margin = " + this.insets.top + " }";
    }
}
